<?php get_header(); ?>

<div class="max-w-7xl mx-auto px-4 py-8">
    <div class="flex flex-col lg:flex-row gap-8">
        <!-- 主内容区 -->
        <main class="flex-1 min-w-0 space-y-4">
            <?php if (have_posts()) : while (have_posts()) : the_post(); ?>
                <article class="bg-white rounded-lg shadow">
                    <div class="flex">
                        <!-- 投票区 -->
                        <div class="w-10 flex flex-col items-center py-2 bg-gray-50 rounded-l-lg">
                            <button onclick="vote(<?php echo get_the_ID(); ?>, 'upvote')" 
                                    class="p-1 hover:bg-gray-200 rounded <?php echo get_user_vote_status(get_the_ID()) === 'up' ? 'text-orange-500' : 'text-gray-400'; ?>">
                                <svg class="w-5 h-5" fill="currentColor" viewBox="0 0 20 20">
                                    <path d="M10 12.5l-5-5h10l-5 5z"/>
                                </svg>
                            </button>
                            <span class="text-xs font-medium my-1"><?php echo get_post_score(); ?></span>
                            <button onclick="vote(<?php echo get_the_ID(); ?>, 'downvote')"
                                    class="p-1 hover:bg-gray-200 rounded <?php echo get_user_vote_status(get_the_ID()) === 'down' ? 'text-blue-500' : 'text-gray-400'; ?>">
                                <svg class="w-5 h-5" fill="currentColor" viewBox="0 0 20 20">
                                    <path d="M10 7.5l5 5H5l5-5z"/>
                                </svg>
                            </button>
                        </div>

                        <!-- 内容区 -->
                        <div class="flex-1 p-4">
                            <!-- 帖子元信息 -->
                            <div class="flex items-center text-xs text-gray-500 mb-2">
                                <a href="<?php echo get_post_type_archive_link('subreddit'); ?>" class="font-medium text-black hover:underline">
                                    r/<?php echo get_post_type(); ?>
                                </a>
                                <span class="mx-1">•</span>
                                <span>Posted by</span>
                                <a href="<?php echo get_author_posts_url(get_the_author_meta('ID')); ?>" class="ml-1 hover:underline">
                                    u/<?php the_author(); ?>
                                </a>
                                <span class="mx-1">•</span>
                                <span><?php echo human_time_diff(get_the_time('U'), current_time('timestamp')); ?> ago</span>
                            </div>

                            <!-- 帖子标题 -->
                            <h2 class="text-lg font-medium mb-2">
                                <a href="<?php the_permalink(); ?>" class="hover:underline">
                                    <?php the_title(); ?>
                                </a>
                            </h2>

                            <!-- 帖子预览 -->
                            <div class="prose prose-sm max-w-none mb-3">
                                <?php the_excerpt(); ?>
                            </div>

                            <!-- 帖子操作栏 -->
                            <div class="flex items-center space-x-4 text-xs text-gray-500">
                                <a href="<?php comments_link(); ?>" class="flex items-center hover:bg-gray-100 px-2 py-1 rounded">
                                    <svg class="w-4 h-4 mr-1" fill="none" stroke="currentColor" viewBox="0 0 24 24">
                                        <path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M8 12h.01M12 12h.01M16 12h.01M21 12c0 4.418-4.03 8-9 8a9.863 9.863 0 01-4.255-.949L3 20l1.395-3.72C3.512 15.042 3 13.574 3 12c0-4.418 4.03-8 9-8s9 3.582 9 8z"/>
                                    </svg>
                                    <?php comments_number('0 comments', '1 comment', '% comments'); ?>
                                </a>
                                <button class="flex items-center hover:bg-gray-100 px-2 py-1 rounded">
                                    <svg class="w-4 h-4 mr-1" fill="none" stroke="currentColor" viewBox="0 0 24 24">
                                        <path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M8.684 13.342C8.886 12.938 9 12.482 9 12c0-.482-.114-.938-.316-1.342m0 2.684a3 3 0 110-2.684m0 2.684l6.632 3.316m-6.632-6l6.632-3.316m0 0a3 3 0 105.367-2.684 3 3 0 00-5.367 2.684zm0 9.316a3 3 0 105.368 2.684 3 3 0 00-5.368-2.684z"/>
                                    </svg>
                                    Share
                                </button>
                                <button class="flex items-center hover:bg-gray-100 px-2 py-1 rounded">
                                    <svg class="w-4 h-4 mr-1" fill="none" stroke="currentColor" viewBox="0 0 24 24">
                                        <path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M5 5a2 2 0 012-2h10a2 2 0 012 2v16l-7-3.5L5 21V5z"/>
                                    </svg>
                                    Save
                                </button>
                            </div>
                        </div>
                    </div>
                </article>
            <?php endwhile; ?>

            <!-- 分页 -->
            <div class="flex justify-center gap-2">
                <?php
                echo paginate_links(array(
                    'prev_text' => __('上一页'),
                    'next_text' => __('下一页'),
                    'class' => 'px-4 py-2 bg-white rounded-lg shadow text-sm hover:bg-gray-50'
                ));
                ?>
            </div>

            <?php else : ?>
                <div class="bg-white rounded-lg shadow p-6 text-center">
                    <p class="text-gray-500">暂无内容</p>
                </div>
            <?php endif; ?>
        </main>

        <!-- 侧边栏 -->
        <aside class="w-full lg:w-80">
            <?php get_sidebar(); ?>
        </aside>
    </div>
</div>

<?php get_footer(); ?> 